package com.ruoyi.system.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.domain.OrderInfo;
import com.ruoyi.system.service.OrderInfoService;
import com.ruoyi.system.webSocket.ChatEndPoint;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author :
 * @date : 2024-10-17 19:57
 * @description :
 **/
@RestController
@RequestMapping("/info/order")
@Slf4j
public class UserController {
    @Resource
    private ChatEndPoint chatEndPoint;

    @Resource
    private OrderInfoService orderInfoService;

    /**
     * 下单
     * @param  ，包含乘客ID预订单ID
     * @param
     * @return
     */
    @PostMapping("/getcoupon")
    public AjaxResult InsertOrder(@RequestBody OrderInfo orderInfo) {
        log.info("下单 orderInfo:{}",orderInfo);

        orderInfoService.save(orderInfo);
        chatEndPoint.sendMessage("有新的订单,订单:出发地"+orderInfo.getDeparture()+"目的地"+orderInfo.getDestination()+"订单号"+orderInfo.getId());
        log.info("有新的订单,订单:出发地"+orderInfo.getDeparture()+"目的地"+orderInfo.getDestination()+"订单号"+orderInfo.getId());

        return AjaxResult.success("下单成功");
    }



}
